package com.itxckf.controller;


import com.itxckf.pojo.Result;
import com.itxckf.utils.UploadFile;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 阿里云 oss 上传文件      文件流
 */
@Slf4j
@RestController
public class OssUploadFileController {
    @Autowired
    private UploadFile uploadFile;
    @PostMapping("/uploadFile")
    public Result upload(@RequestParam("file") MultipartFile file) throws IOException {
        log.info("上传图片，{}",file);
        if(file != null){
            String url = uploadFile.UploadFile(file);
            log.info("文件上传完成，文件访问的url:{}",url);
            return Result.success(url);
        }
        return Result.error("上传失败！");
    }
}
